<?php
require_once("../class2.php");
require_once(HEADERF);
require_once("./cms/includes/require_all.php");
$database->cyr_chars();
$page_class = "PlayON"; //Key for non-users
$user_id = USERID;
$user_name = USERNAME;
ramka("open");
?>
<link rel="stylesheet" type="text/css" href="./vts/css/main.css" />
<script type="text/javascript" src="./vts/js/wz_tooltip.js"></script>
<style type="text/css">
	#pendingtranses {
		background: none repeat scroll 0% 0% black;
		border-top-left-radius: 25px;
		border-top-right-radius: 25px;
		border-top: 3px solid white;
		font-size: 20px;
		color: gold;
		padding: 3px 15px;
		opacity: 0.5;
	}
	#pendingtranses:hover {opacity:0.75;}
	.opaque {opacity:0.25;}
	.opaque:hover {opacity:1;}
	.gameimghover {
		opacity:1;
		border: 1px solid black;
		border-top: 6px solid black;
		border-radius: 40px 40px 10px 10px;
		margin-top: 10px;
	}
	.gameimghover:hover {opacity:0.25;}
</style>
<?php
$q = "SELECT * FROM admin_panel";
$r = mysql_query($q);
$array_games_trans_tables = array();
while($a = mysql_fetch_array($r)){
	$k = (string)$a['game_name'];
	$v = (string)$a['game_prefix'];
	$array_games_trans_tables[$k] = $v;
}

foreach($array_games_trans_tables as $k => $v){
	$q = "select COUNT(id) as count from cms_usertests where game='$v' and rate='-1'";
	$r = mysql_fetch_assoc(mysql_query($q));
	$pending_candidates[$k] = $r['count'];
}

foreach($array_games_trans_tables as $k => $v){
	$q = "select status from ".$v."_translations where status like 'В процес на проверка...%'";
	$r = mysql_query($q);
	$array_games_trans_tables[$k] = mysql_num_rows($r);
}

echo "<table width=100%><tr>";
if(check_class($page_class) or $user_name == "e-VIL" or $user_name == "Zlo" or $user_name == "mitaka18" or $user_name == "tsetse" or $user_name == "kockata1"){
	echo '<td ALIGN="left"><a href="vts/" class="forumheader4" style="font-size:14px; margin-left:10px;">Админ панел</a><a href="cms/dict.php" class="forumheader4" style="font-size:14px; margin-left:10px;">Речник</a><a href="repeat_tr.php" class="forumheader4" style="font-size:14px; margin-left:10px;">Повторения</a><a href="cms/ipact.php" class="forumheader4" style="font-size:14px; margin-left:10px;">Активност</a></td>';
}
if (USERNAME!='USERNAME') {$addMyTranslations_button= '<a href="cms/utest.php?usr='.USERNAME.'&pg=1" class="forumheader4" style="font-size:14px; margin-right:10px;">Моите преводи</a>';}
echo '<td ALIGN="right">'.$addMyTranslations_button.' <a href="cms/stats.php" class="forumheader4" style="font-size:14px; margin-right:10px;">Статистика</a></td></tr></table>';

echo "<center class='forumheader4' style='margin-top:-20px; margin-left:-1px; padding-bottom:10px;'><h1 style='border-bottom:0px; cursor:default;' class='unselectable'><br>ИГРИ ЗА ПРЕВОД</h1></center>";


$array_access = array(0 => 1, 1 => USER, 2 => check_class($page_class));
$array_finished_games = array();
foreach($array_access as $k => $v){
	if($v or $user_name == "e-VIL" or $user_name == "Zlo" or $user_name == "mitaka18" or $user_name == "tsetse" or $user_name == "kockata1"){
		$q = "select * from admin_panel where level_access = $k order by game_imp desc";
		$r = mysql_query($q);
		$counter = 1;
		if($k == 2){
			echo "<center class='forumheader4' style='margin-left:-1px; padding-bottom:10px;'><h1 style='border-bottom:0px;'>ЕКИПНИ ИГРИ</h1></center>";
		}
		echo "<table cellpadding='30' style='text-align: center; width:100%;'><tr>";
		while($a = mysql_fetch_array($r)){
			if($a['game_show'] == 1){
				if($a['urlprefix'] == null) {
					$a['urlprefix']=str_getBetween(trim($a['game_link']),"game=","");
					mysql_query("UPDATE admin_panel SET urlprefix='$a[urlprefix]' WHERE game_prefix='$a[game_prefix]'");
				}
				if($a['game_percent'] == 100){
					if($array_access[2]){
						$array_finished_games[$a['id']] = 1;
					}
					else{
						$array_finished_games[$a['id']] = 0;
					}
					$counter--;
				}
				if(check_class($page_class)) {
					$floatingbuttons_left="<div style='position:absolute;padding-left:8px;' class='unselectable'><a href='vts/admin_edit.php?id=$a[id]' title='Настройки на играта' class='opaque'><img src='http://www.tnsamb.gov.in/images/submenus/tools.png'/></a><br><a href='cms/dict.php?game=$a[urlprefix]' title='Речник на играта' class='opaque'><img src='http://www.manorlodge.org.uk/images/accessibilitya-clear.png'/></a><br>";
					$floatingbuttons_right="";
					if (isset($pending_candidates[$a['game_name']]) and $pending_candidates[$a['game_name']]>0) {
						$floatingbuttons_right.="<a href='cms/ratinguser-app.php?game=$a[urlprefix]' class='button textYELLOW'>".$pending_candidates[$a['game_name']]."</a>";
					}
					$floatingbuttons_right.="</div>";
				}
					
				if(check_class($page_class)) { $a['wordspercent']= "(".round(($a['wordsdone']/$a['wordsall'])*100, 2)."%)"; }
				$wordsecho="<br><span class='smalltext' title='Брой думи\nПреведени: $a[wordsdone]\nОбщо: $a[wordsall]' style='cursor:help;'><span class='textGREEN'>$a[wordsdone]</span><span class='textGREY'> / </span><span class='textRED'>$a[wordsall]</span> $a[wordspercent]</span>";
				if (USERNAME == "Mnementh") {
					$charall_tr = round($a['charall_translated']/1800);
					$charall    = round($a['charall']/1800);
					$charpercent= round(($a['charall_translated']/$a['charall'])*100, 2);
					$charsecho="<br><span class='smalltext' title='Машинописни страници\nПреведени: $charall_tr\nОбщо: $charall' style='cursor:help;'><span class='textGREEN'>$charall_tr</span><span class='textGREY'> / </span><span class='textRED'>$charall</span> ($charpercent%)</span>";
				} else $charsecho="";
				$waitingecho="<div style='margin-top:-47px;' title='Има чакащи одобрение реплики.'><img src='vts/images/waitingecho.gif' width='175'></div>";
				$waitingecho.="<center style='margin-top:-25px;margin-bottom:4px'><a href='cms/listtranslations.php?game=$a[urlprefix]' id='pendingtranses' title='Отвори списъка на чакащите одобрение'><span style='opacity:1 !important;'>$a[pendingtranses]</span></a></center>";
						$pp=ceil($a['game_percent']*2);
						$pt_temp = floor($a['game_percent']*5.1);
						if($pt_temp > 255){
							$green = 255;
							$red = $pt_temp - $green;
						}
						else{
							$green = $pt_temp;
							$red = 0;
						}
						$pt = "rgb(".(255-$red).",".(0+$green).",".(0).")";
				if($array_games_trans_tables[$a['game_name']] != 0 and $a['game_percent'] != 100){
						echo '<td class="forumheader3" width:33% style="vertical-align:top; padding-top:10px;">'.$floatingbuttons_left.$floatingbuttons_right.'<a href="'.$a['game_link'].'" onmouseover="Tip(\''.addslashes(preg_replace("/[\r\n]/", "<br>", $a['game_desc'])).'\', BORDERCOLOR, \'#006699\', BGCOLOR, \'#FFFF66\', FONTFACE, \'Helvetica, Arial, sans-serif\', FONTSIZE, \'14px\', FONTCOLOR, \'#006699\',FONTWEIGHT, \'BOLD\', PADDING, \'10\')" onmouseout="UnTip()"><img src="'.$a['game_cover'].'" width="175" height="250" style="display: inline-block;" class="gameimghover"><div></div>'.$waitingecho.'</a><br><div class="forumheader unselectable" style="color: #666; font-size: 14px; padding-right: 10px; padding-left: 10px; cursor:default;"><span class="textBLUE" style="font-weight:bold;">'.$a['game_name'].' <span class="textDBLUE">['.$a['game_platform'].']</span></span><center><div style="width:200px; height:15px; border: 1px solid black; background-color:grey;" align="left"><div style="width:'.$pp.'px; background-color:'.$pt.'; height:15px;"></div></div></center><div style="margin-top:-17px;margin-bottom:-17px;" class="textBLACK">'.$a['rows_translated'].'/'.$a['rows_all'].' ('.$a['game_percent'].'%)</div>'.$wordsecho.'</td>';
				}
				elseif($array_games_trans_tables[$a['game_name']] == 0 and $a['game_percent'] != 100){
						echo '<td class="forumheader3" width=33% style="vertical-align:top; padding-top:10px;">'.$floatingbuttons_left.$floatingbuttons_right.'<a href="'.$a['game_link'].'" onmouseover="Tip(\''.addslashes(preg_replace("/[\r\n]/", "<br>", $a['game_desc'])).'\', BORDERCOLOR, \'#006699\', BGCOLOR, \'#FFFF66\', FONTFACE, \'Helvetica, Arial, sans-serif\', FONTSIZE, \'14px\', FONTCOLOR, \'#006699\',FONTWEIGHT, \'BOLD\', PADDING, \'10\')" onmouseout="UnTip()"><img src="'.$a['game_cover'].'" width="175" height="250" style="display: inline-block;" class="gameimghover"></a><br><div class="forumheader unselectable" style="color: #666; font-size: 14px; padding-right: 10px; padding-left: 10px; cursor:default;"><span class="textBLUE" style="font-weight:bold;">'.$a['game_name'].' <span class="textDBLUE">['.$a['game_platform'].']</span></span><center><div style="width:200px; height:15px; border: 1px solid black; background-color:grey;" align="left"><div style="width:'.$pp.'px; background-color:'.$pt.'; height:15px;"></div></div></center><div style="margin-top:-17px;margin-bottom:-17px;" class="textBLACK">'.$a['rows_translated'].'/'.$a['rows_all'].' ('.$a['game_percent'].'%)</div>'.$wordsecho.'</td>';
				}
				if($counter % 3 == 0){
					echo "</tr><tr>";
				}
				$counter++;
			}
		}
		if($counter--%3!=0){
			while($counter%3!=0){
				echo "<td class='forumheader3'></td>";
				$counter++;
			}
		}
		echo "</tr></table>";
	}
}

echo "<center class='forumheader4' style='margin-left:-1px; padding-bottom:10px;'><h1 style='border-bottom:0px; cursor:default;' class='unselectable'>ТЕСТВАТ СЕ:</h1></center>";
echo "<table cellpadding='30' style='text-align: center; width:100%;'><tr>";
$counter = 1;
foreach($array_finished_games as $k => $v){
	$q = "select * from admin_panel where id = $k";
	$r = mysql_query($q);
	if($a = mysql_fetch_array($r)){
			echo '<td class="forumheader3" width=33% style="vertical-align:top;"><a href="'.$a['game_link'].'" onmouseover="Tip(\''.addslashes(preg_replace("/[\r\n]/", "<br>", $a['game_desc'])).'\', BORDERCOLOR, \'#006699\', BGCOLOR, \'#FFFF66\', FONTFACE, \'Helvetica, Arial, sans-serif\', FONTSIZE, \'14px\', FONTCOLOR, \'#006699\',FONTWEIGHT, \'BOLD\', PADDING, \'10\')" onmouseout="UnTip()"><img src="'.$a['game_cover'].'" width="175" height="250" style="display: inline-block;" class="gameimghover"></a><br><div class="forumheader3 textWHITE" style="font-size: 14px;">'.$a['game_name'].' ['.$a['game_platform'].']<br><span class="textYELLOW" style="font-size: 12px;">В процес на тестване!</span></div></td>';
		if($counter % 3 ==0){
			echo "</tr><tr>";
		}
		$counter++;
	}
}
if($counter--%3!=0){
	while($counter%3!=0){
		echo "<td class='forumheader3'></td>";
		$counter++;
	}
}
echo "</tr></table>";

ramka("close");
require_once(FOOTERF);
?>